/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package billingServer;

import java.io.Serializable;

/**
 * Represents the bill for one auction of one user.
 * Price is calculated based on current PriceSteps.
 * @author Gruppe 95
 */
public class AuctionBill implements Serializable {
    private long auctionID;
    private double strikePrice;
    private double feeFixed;
    private double feeVariable;
    private double feeTotal;
    
    /**
     * Create new AuctionBill.
     * Calculate price based on current PriceSteps
     * @param auctionID
     * @param strikePrice
     * @param priceSteps 
     */
    public AuctionBill(long auctionID, double strikePrice, PriceSteps priceSteps) {
        this.auctionID = auctionID;
        this.strikePrice = strikePrice;
        PriceStep priceStep = null;
        for(PriceStep p : priceSteps.getPriceSteps()) {
            if(strikePrice >= p.getStartPrice() && strikePrice <= p.getEndPrice()) {
                priceStep = p;
            }
        }
        if (priceStep == null) {
            feeFixed = feeVariable = feeTotal = 0;
        } else {
            feeFixed = priceStep.getFixedPrice();
            feeVariable = priceStep.getVariablePricePercent();
            feeTotal = feeFixed;
            if (strikePrice > 0) {
                feeTotal += feeVariable*strikePrice;
            }
        }
        
    }
    
    /**
     * Create string-representation of one AuctionBill.
     * Values in one row divided by tap-stop.
     * @return 
     */
    public String toLine() {
        return auctionID + "\t" + "\t" + strikePrice + "\t" + "\t"
                + feeFixed + "\t" + "\t" + feeVariable + "\t" + "\t" + feeTotal;
    }
}
